<?php defined('InShopNC') or exit('Access Invalid!');?>

<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <a class="back" href="index.php?act=marketing_activity&op=marketing_activity" title="返回活动列表"><i class="fa fa-arrow-circle-o-left"></i></a>
      <div class="subject">
        <h3><?php echo $lang['activity_index_manage'];?> - <?php echo $lang['nc_new'];?></a></h3>
        <h5><?php echo $lang['activity_index_manage_subhead']; ?></h5>
      </div>
    </div>
  </div>
  <form id="add_form" method="post" enctype="multipart/form-data">
    <input type="hidden" name="form_submit" value="ok" />
    <div class="ncap-form-default">
      <dl class="row">
        <dt class="tit">
          <label for="marketing_activity_title"><em>*</em><?php echo $lang['activity_index_title'];?></label>
        </dt>
        <dd class="opt">
          <input type="text" id="marketing_activity_title" name="marketing_activity_title" class="input-txt" >
          <span class="err"></span>
          <p class="notic">
            <?php echo $lang['activity_new_title_tip'];?>
          </p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label><em>*</em><?php echo $lang['activity_index_apply_start'];?></label>
        </dt>
        <dd class="opt">
          <input type="text" id="marketing_activity_apply_start_date" name="marketing_activity_apply_start_date" class="input-txt" />
          <span class="err"></span>
          <p class="notic"></p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label><em>*</em><?php echo $lang['activity_index_apply_end'];?></label>
        </dt>
        <dd class="opt">
          <input type="text" id="marketing_activity_apply_end_date" name="marketing_activity_apply_end_date" class="input-txt" />
          <span class="err"></span>
          <p class="notic"></p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label for="store_goods_limit"><em>*</em><?php echo $lang['activity_store_goods_limit'];?></label>
        </dt>
        <dd class="opt">
          <input type="text" id="store_goods_limit" name="store_goods_limit" class="input-txt" value="0">
          <span class="err"></span>
          <p class="notic"><?php echo $lang['activity_index_help5'];?></p>
        </dd>
      </dl>

      <dl class="row" style="display:block;">
        <dt class="tit">
          <label><em>*</em><?php echo $lang['activity_index_type'];?></label>
        </dt>
        <dd class="opt">
          <select name="marketing_activity_type" id="change_type">
            <optgroup>
            <?php foreach($output['marketing_activity_type'] as $k => $v):?>
              <option value="<?=$k?>"><?=$v?></option>
            <?php endforeach;?>
            </optgroup>
          </select>
          <span class="err"></span>
          <p class="notic"><?php echo $lang['activity_new_type_tip'];?></p>
        </dd>
      </dl>

        <dl class="row" id="min_num_display" style="display: none">
            <dt class="tit">
                <label for="min_num"><em>*</em>参团人数</label>
            </dt>
            <dd class="opt">
                <input type="number" id="min_num" name="min_num" class="input-txt" value="0" min="0">
                <span class="err"></span>
                <p class="notic">建议设置3到5人，因人数越多成团机率越小</p>
            </dd>
        </dl>

      <dl class="row">
        <dt class="tit">
          <label><em>*</em><?php echo $lang['activity_index_start'];?></label>
        </dt>
        <dd class="opt">
          <input type="text" id="marketing_activity_start_date" name="marketing_activity_start_date" class="input-txt" />
          <span class="err"></span>
          <p class="notic"></p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label><em>*</em><?php echo $lang['activity_index_end'];?></label>
        </dt>
        <dd class="opt">
          <input type="text" id="marketing_activity_end_date" name="marketing_activity_end_date" class="input-txt"/>
          <span class="err"></span>
          <p class="notic"></p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label><em>*</em><?php echo $lang['activity_index_banner'];?></label>
        </dt>
        <dd class="opt">
          <div class="input-file-show"><span class="type-file-box">
            <input type="file" class="type-file-file" id="marketing_activity_banner" name="marketing_activity_banner" size="30" hidefocus="true"  nc_type="upload_marketing_activity_banner" title="点击按钮选择文件并提交表单后上传生效">
            </span></div>
          <span class="err"></span>
          <p class="notic"><?php echo $lang['activity_new_banner_tip'];?></p>
        </dd>
      </dl>
      <dl class="row" style="display:none;">
        <dt class="tit">
          <label><?php echo $lang['activity_new_style'];?></label>
        </dt>
        <dd class="opt">
          <select id="marketing_activity_style" name="marketing_activity_style">
            <option value="default_style"><?php echo $lang['activity_index_default'];?></option>
          </select>
          <span class="err"></span>
          <p class="notic"><?php echo $lang['activity_new_style_tip'];?></p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit"><?php echo $lang['activity_new_desc']; ?></dt>
        <dd class="opt">
          <?php showEditor('marketing_activity_desc','','600px','400px','visibility:hidden;',"true",$output['editor_multimedia']);?>
          <span class="err"></span>
          <p class="notic"></p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label for="marketing_activity_sort"><em>*</em><?php echo $lang['nc_sort'];?></label>
        </dt>
        <dd class="opt">
          <input type="text" id="marketing_activity_sort" name="marketing_activity_sort" class="input-txt" value="0">
          <span class="err"></span>
          <p class="notic"><?php echo $lang['activity_new_sort_tip1'];?></p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label for="marketing_activity_state"><?php echo $lang['activity_openstate'];?></label>
        </dt>
        <dd class="opt">
          <div class="onoff">
            <label for="marketing_activity_state1" class="cb-enable selected" ><?php echo $lang['activity_openstate_open'];?></label>
            <label for="marketing_activity_state0" class="cb-disable"><?php echo $lang['activity_openstate_close'];?></label>
            <input id="marketing_activity_state1" name="marketing_activity_state" checked="checked" value="1" type="radio">
            <input id="marketing_activity_state0" name="marketing_activity_state" value="0" type="radio">
          </div>
          <p class="notic"></p>
        </dd>
      </dl>
      <dl class="row">
        <dt class="tit">
          <label for="marketing_activity_show"><?php echo $lang['activity_if_show'];?></label>
        </dt>
        <dd class="opt">
          <div class="onoff">
            <label for="marketing_activity_show1" class="cb-enable selected" ><?php echo $lang['activity_showstate_open'];?></label>
            <label for="marketing_activity_show0" class="cb-disable"><?php echo $lang['activity_showstate_close'];?></label>
            <input id="marketing_activity_show1" name="marketing_activity_show" checked="checked" value="1" type="radio">
            <input id="marketing_activity_show0" name="marketing_activity_show" value="0" type="radio">
          </div>
          <p class="notic"></p>
        </dd>
      </dl>
      <div class="bot"><a href="JavaScript:void(0);" class="ncap-btn-big ncap-btn-green" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></div>
    </div>
  </form>
</div>
<script src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css"  />
<script>
    /*显示隐藏砍价和拼团参团人数*/
    $("#change_type").change(function(){
        if($('#change_type').val() == 3 || $('#change_type').val() == 4){
            $('#min_num_display').css('display','block');
        }else{
            $('#min_num_display').css('display','none');
        }
    });
//按钮先执行验证再提交表单
$(function(){$("#submitBtn").click(function(){
    if($("#add_form").valid()){
     $("#add_form").submit();
  }
  });
});

$(document).ready(function(){
  $("#marketing_activity_apply_start_date,#marketing_activity_apply_end_date,#marketing_activity_start_date,#marketing_activity_end_date").datetimepicker({controlType: 'select'});

  $('#marketing_activity_start_date').change(function(){
      $("#add_form").valid();
  });

  /**
   * 开始时间不能大于结束时间
   */
  jQuery.validator.methods.compareDate = function(value, element, param) {
      //补全yyyy-MM-dd HH:mm:ss格式，兼容ie，firefox
      var startDate = jQuery(param).val() + ":00";
      value = value + ":00";

      var date1 = new Date(Date.parse(startDate.replace(/-/g, "/")));
      var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
      return date1 < date2;
  };

  jQuery.validator.methods.compareDate1 = function(value, element, param) {
      //补全yyyy-MM-dd HH:mm:ss格式，兼容ie，firefox
      var startDate = jQuery(param).val() + ":00";
      value = value + ":00";

      var date1 = new Date(Date.parse(startDate.replace(/-/g, "/")));
      var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
      return date1 < date2;
  };

  $("#add_form").validate({
    errorPlacement: function(error, element){
      var error_td = element.parents('dl').find('span.err');
            error_td.append(error);
        },
        rules : {
          marketing_activity_title: {
            required : true
          },
          marketing_activity_apply_start_date: {
            required : true,
            date     : false
          },
          marketing_activity_apply_end_date: {
            required : true,
            date     : false,
            compareDate : '#marketing_activity_apply_start_date'
          },
          marketing_activity_start_date: {
            required : true,
            date     : false,
            compareDate1 : '#marketing_activity_apply_start_date'
          },
          marketing_activity_end_date: {
            required : true,
            date     : false,
            compareDate : '#marketing_activity_start_date',
            compareDate1 : '#marketing_activity_apply_end_date'
          },
          marketing_activity_banner: {
            required : true,
            accept   : 'png|jpe?g|gif'
          },
          marketing_activity_sort: {
            required : true,
            min      : 0,
            max      : 255
          },
          store_goods_limit: {
            required : true,
            min      : 0,
            max      : 255
          }
        },
        messages : {
          marketing_activity_title: {
            required : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_title_null'];?>'
          },
          marketing_activity_apply_start_date: {
            required : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_applystartdate_null'];?>'
          },
          marketing_activity_apply_end_date: {
            required : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_applyenddate_null'];?>',
            compareDate: "报名截至时间必须大于报名开始时间!"
          },
          marketing_activity_start_date: {
            required : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_startdate_null'];?>',
            compareDate1: "报名开始时间不能大于等于活动开始时间"
          },
          marketing_activity_end_date: {
            required : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_enddate_null'];?>',
            compareDate: "结束日期必须大于开始日期!",
            compareDate1: "报名结束时间不能大于等于活动结束时间"
          },
          marketing_activity_banner: {
                required : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_banner_null'];?>',
            accept   : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_ing_wrong'];?>'
          },
          marketing_activity_sort: {
            required : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_sort_null'];?>',
            min:'<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_sort_minerror'];?>',
            max:'<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_sort_maxerror'];?>'
          },
          store_goods_limit: {
            required : '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_storegoodslimit_null'];?>',
            min:'<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_storegoodslimit_minerror'];?>',
            max:'<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_storegoodslimit_maxerror'];?>'
          }
        }
  });

});

$(function(){
// 模拟活动页面横幅Banner上传input type='file'样式
  var textButton="<input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='选择上传...' class='type-file-button' />"
    $(textButton).insertBefore("#marketing_activity_banner");
    $("#marketing_activity_banner").change(function(){
       $("#textfield1").val($("#marketing_activity_banner").val());
    });
});
</script>